<?php
namespace app\shop\controller;
use app\AdminRest;
use app\shop\model\PurchaseCate;
use app\shop\model\PurchaseCompany;
use think\App;
use app\shop\model\PurchaseTmp as Model;

use think\facade\Db;

class AdminPurchase extends AdminRest
{

    protected $model;


    public function __construct(App $app) {

        parent::__construct($app);

        $this->model = new Model();

    }


    /**
     * @author chenniang
     * @DataTime: 2020-06-22 09:34
     * @功能说明:自提点列表
     */
    public function tmpList(){

        $input = $this->_param;

        $dis[] = ['uniacid','=',$this->_uniacid];
        //未删除
        $dis[] = ['status','>',-1];

        if(!empty($input['title'])){

            $dis[] = ['title','like','%'.$input['title'].'%'];
        }

        $data = $this->model->tmpList($dis,$input['limit']);

        return $this->success($data);

    }

    /**
     * @author chenniang
     * @DataTime: 2020-12-09 14:35
     * @功能说明:列表
     */
    public function tmpInfo(){

        $input = $this->_param;

        $data  = $this->model->tmpInfo(['id'=>$input['id']]);

        $cate_model = new PurchaseCate();

        $company_model = new PurchaseCompany();

        $data['cate']  = $cate_model->getCateId($data);

        $data['company'] = $company_model->getCompanyId($data);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-12-09 15:19
     * @功能说明:添加
     */
    public function tmpAdd(){

        $input = $this->_input;

        $input['uniacid'] = $this->_uniacid;

        $res = $this->model->tmpAdd($input);

        return $this->success($res);


    }


    /**
     * @author chenniang
     * @DataTime: 2020-12-09 15:20
     * @功能说明:编辑
     */
    public function tmpUpdate(){

        $input = $this->_input;

        $dis = [

            'id' => $input['id'],

        ];

        $input['uniacid'] = $this->_uniacid;

        $res = $this->model->tmpUpdate($dis,$input);

        return $this->success($res);


    }


    /**
     * @author chenniang
     * @DataTime: 2020-12-09 15:20
     * @功能说明:编辑
     */
    public function tmpStatusUpdate(){

        $input = $this->_input;

        $dis = [

            'id' => $input['id']
        ];

        $res = $this->model->where($dis)->update(['status'=>$input['status']]);

        return $this->success($res);


    }









}
